package managedbean;

import entity.SaleLead;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import session.stateless.SaleLeadBeanLocal;

@ManagedBean
@ViewScoped
public class DeleteSaleLeadManagerBean implements Serializable
{
    @EJB
    private SaleLeadBeanLocal saleLeadBeanLocal;
    private SaleLead saleLeadToDelete;

    public SaleLead getSaleLeadToDelete() {
        return saleLeadToDelete;
    }

    public void setSaleLeadToDelete(SaleLead saleLeadToDelete) {
        this.saleLeadToDelete = saleLeadToDelete;
    }
    
    
    public DeleteSaleLeadManagerBean() {}
    
    public void initView(PhaseEvent event)
    {
        if (saleLeadToDelete ==null)
        {
            saleLeadToDelete = (SaleLead) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedSaleLead");
        }
    }
    
    
    public void deleteSaleLead(ActionEvent event)
    {
        saleLeadBeanLocal.deleteSaleLead(saleLeadToDelete.getSaleLeadId());
    }   
    
}
